<?php
namespace Api\Controller;
use Think\Controller;
class CsController extends Controller {

	private $m = NULL;
	private $navName = '测试账户录入';
        
        /*  2017-06-14  liuq
	 *  用户注册
	 *
	 */
  
        
        
        public  function  pic(){
           $img =  '73001500448421.jpeg';
            
           //$pics =   rtrim($pics, "|");
           
           
     if(!is_array($img)){
       $img=explode("|", $img);
       }
       for($i=0;$i<count($img);$i++){
           $newImgType= substr($img[$i],0,strrpos($img[$i],';'));  //图片的类型
           $base=substr($img[$i],strrpos($img[$i],';')+1);
           $a=explode(',',$base);
           $types=explode('/',$newImgType);
           $type=$types[1];
       //    dump($type);exit;
           $filename = rand(0,100000).time().".".$type; 
//           $xmlstr=base64_decode($a[1]);
//           makeDir($address);
//           $file = fopen($address.$filename,"w");//打开文件准备写入  
//           fwrite($file,$xmlstr);//写入
//           fclose($file);//关闭
           $fileaddress[]=$filename;
//           $fileaddress[]=$filename;
       } 
       $info=implode('|',$fileaddress);
       //return $info.'|';
       
       dump($info);exit;
       return $info;
           
       
            
            
        }
        public  function  time(){
            
            echo strtotime("2017-08-21 16:00:00")."<br/>";
              echo strtotime("2017-08-18 16:00:00")."<br/>";
                echo strtotime("2017-08-17 16:00:00")."<br/>";
                echo strtotime(date(' H:i'))."<br/>";
                echo  date('H:i', 1499321460);
                  
        }
        
        
        public  function  testorder(){
          
            $info['order_no'] = $this->GetorderStr();
            dump($info);exit;
        }
        
      
        
        function GetorderStr(){

        $newoutputstr=date('Ymdhis').rand(1000,9999);
  
        $num = M("shop_product_order")->where('order_no="'.$newoutputstr.'"')->count();
	
  	if($num ==0){
	    return $newoutputstr;
	}else{
            return GetorderStr();	
	}
  
   }


        //重设密码  获取短信验证码  并存到session中
         public function find_sms(){
			//$mobile = I('phone');
                        $mobile = "15711117399";
                        
			if(empty($mobile)){
			  returnmemberError("1", "电话号码不能为空");exit;
			}
                        $is_phone = M('member')->where('phone="'.$mobile.'"')->getField('id');
                        print_r($is_phone);exit;
                        if( $is_phone == false){
                            dump('55656565');exit;
                        returnmemberError("1", "该用户不存在");exit;
                        }
			$sms=$this->find_send_phone($mobile);
                        //$rcode=$sms[0];  //返回状态值
                        //  if( $rcode ==22){
			//   exit('1小时内同一手机号发送次数超过限制');
			//   }
			// $code=(int)$sms[1];   //返回验证码随机6位
		        if($sms){
                                returnApiresult('0','发送成功');exit;
                        }else{
                               returnmemberError("1", "发送验证码过于频繁");exit;
                        }
    	
		}
                
        public  function  test02(){
           $tell = '13624012805';
           $code= rand(100000,999999);
           F('liuq/up2/'.$tell,$code); 
        } 
           
       public  function test033(){
            $tell = '13624012805';
            $arr = F('liuq/up2/'.$tell);
            dump($arr);
       }
                
        public    function  test (){
            
//        $tell = '13624012805';    
//        $code= rand(100000,999999);//随机六位验证码
//       // $_SESSION['sms_mobile_code'] = $code;
//        F('liuq/reg/'.$tell,$code);
       // F('data','test data');
            
            
             $code= rand(100000,999999);//随机六位验证码
                     //  F('liuq/up/'.$tell,$code);
                      $_SESSION['sms_mobile_code'] = $code;
                      
                      dump($_SESSION['sms_mobile_code']);exit;
        }
        
        
         public    function  test01 (){
            
      
         $data=F('liuq/reg/regcode');
         print_r($data);
        }
        //手机验证码 - 注册
        public  function  reg_one(){
            
               $phone = I('phone');
               $code = I('code');
               if($code == '' || $phone == ''){
                   returnmemberError("1", "您的信息没有填写完整");exit;
               }
               //防短信轰炸机
               if(empty($_SESSION['sms_mobile'])){exit('非法请求');}
               
                $is_phone = M('member')->where('phone="'.trim(I('phone')).'"')->getField('id');
                if($is_phone>0){
                    returnmemberError("1", "该电话已经被注册过");exit;
                }
                
                
                if( $code !=  $_SESSION['sms_mobile_code'] ){
                    returnmemberError("1", "验证码填写错误");exit;
                }  else {
                   returnApiresult("0", "成功");exit;
                }
                
            
        }
        
        
        
        public function reg_second(){
            $phone = I('phone');//前段存
            $password = I('password');
            $twicepass = I('twicepass');
            if($password == '' || $twicepass == ''){
                   returnmemberError("1", "您的信息没有填写完整");exit;
             }
             
             if($twicepass != $password){
                   returnmemberError("1", "两次输入的密码不相符");exit;
             }else{
             $info['phone'] =  $phone;
             $info['password'] = md5($password);
             $info['add_time']  = time();
             $info['mem_type'] = 2;
             $newId = M('member')->add($info);
                if($newId){
                      $data['cid'] = $newId;//生成新用户ID
                      returnApiData('0','注册成功',$data);exit;		
                }else{
                     returnmemberError("1", "注册失败");exit;
                }
             }
         }
         
         
         public  function  reg_detail(){
             $info['cid'] = I('cid');//前段存   $data['cid']
             
             $info['nickname'] = I('nickname');
             $info['phone'] = I('phone');
             $info['major'] = I('major');
             
             $info['cus_prv'] = I('prv_id');
             $info['cus_city'] = I('city_id');
             $info['cus_school'] = I('school_id');
             
             //$info['std_level'] = I('std_level');
             if( I('std_level') == '大一'){
                 $info['std_level'] = 1;
             }
             
              if( I('std_level') == '大二'){
                 $info['std_level'] = 2;
             }
             
              if( I('std_level') == '大三'){
                 $info['std_level'] = 3;
             }
             
              if( I('std_level') == '大四'){
                 $info['std_level'] = 4;
             }
             
             if($info){
                  $result = M('customer')->add($info);
                  if( $result ){
                       returnApiresult("0", "成功");exit;
                  }
                  
             }
             
             
             
         }
    public  function  test03(){
        
        
          $data = M('shop_evaluate')->where('mid=9')->order('add_time desc')->find();
          $pics = $data['evaluate_pics'];
          
            if(!is_array($pics)){
       $pics=explode("|", $pics);
       }
          
          print_r($pics);exit;
    }     

   //手机多张图片上传
function allImg($s_imgphoto,$address,$sign,$day){
    if(!is_array($s_imgphoto)){
       $s_imgphoto=explode("|", $s_imgphoto);
       }
       $address=ltrim($address,'/');
     foreach ($s_imgphoto as $key => $value) {
            $newImgType[$key] = substr($value,0,strrpos($value,','));  //图片的类型
            $post=strrpos($value,',')+1;
            $newImgbase64[$key] = substr($value,$post);  
            $filename = rand(0,100000).time().".".$newImgType[$key]; //图片二进制流
            $xmlstr=base64_decode($newImgbase64[$key]);
            $jpg = $xmlstr; //得到post过来的二进制原始数据
             if($day==1){
               $y=date("Y",time());
               $m=date("m",time());
               $d=date("d",time());
               $day=$y.'-'.$m.'-'.$d;
               $address=$address.$day.'/';
                       }
            makeDir($address);
            $file = fopen($address.$filename,"w");//打开文件准备写入  
            $fileaddressS_imgphoto[$key]='/'.$address.$filename.'|';
            fwrite($file,$jpg);//写入
            fclose($file);//关闭
        } 
        foreach ($fileaddressS_imgphoto as $key => $value) {
          $s_imgphotoUrlAll.=$value;  //多张图片拼接成一个字符串
        }
        
        $s_imgphotoUrlAll=substr($s_imgphotoUrlAll, 0, -1);
        $s_imgphotoUrlAll=ltrim($s_imgphotoUrlAll,'/');
         // $_POST['s_imgphoto']=$s_imgphotoUrlAll;
        return '/'.$s_imgphotoUrlAll;
}
	
//	测试验证码错误

        
                     //修改密码  获取短信验证码  并存到session中
         public function up_sms(){
			$mobile = I('phone');
                        if(empty($mobile)){
			  returnmemberError("1", "电话号码不能为空");exit;
			}
                        $is_phone = M('member')->where('phone="'.$mobile.'"')->getField('id');
                        if( $is_phone == false){
                        returnmemberError("1", "该用户不存在");exit;
                        }
			$sms=$this->up_send_phone($mobile);
                       
		        if($sms){
                                returnApiresult('0','发送成功');exit;
                        }else{
                               returnmemberError("1", "发送验证码过于频繁");exit;
                        }
    	
		}
                
    
         public  function   up_pass(){
                             $phone = I('phone');
                             $code = I('code');
                             if($code == '' || $phone == ''){
                               returnmemberError("1", "您的信息没有填写完整");exit;
                                 //  echo "您的信息没有填写完整";exit;
                             }
                             $is_phone = M('member')->where('phone="'.trim(I('phone')).'"')->getField('id');
                             if( $is_phone == false){
                                  returnmemberError("1", "该用户不存在");exit;
                             }else{
                                   $sms_mobile_code = F('liuq/up/'.$phone);
                                   if( $code !=  $sms_mobile_code ){
                                   //echo "验证码填写错误";exit;
                                returnmemberError("1", "验证码填写错误");exit;
                                   } else {
                                  // $data['phone'] = $phone;//放在第二页手机号位置
                                  // $data['cid'] = $is_phone;
                                  // returnApiData('0','成功',$data);exit;	
                                     returnApiresult("0", "成功");exit;
                                   }
                             }

                }

        public function up_send_phone($tell){
                      import('Org.Alidayu.top.TopClient');
                      import('Org.Alidayu.top.ResultSet');
                      import('Org.Alidayu.top.RequestCheckUtil');
                      import('Org.Alidayu.top.TopLogger');
                      import('Org.Alidayu.top.request.AlibabaAliqinFcSmsNumSendRequest');
                      $c = new \TopClient;
                      $c->appkey = '23699407';  
                      $c->secretKey = '9db1f1f2185271c0ed07f5aed816fce1';
                      $req = new \AlibabaAliqinFcSmsNumSendRequest;
                      $req ->setExtend( "123456" );
                      $req ->setSmsType( "normal" );
                      $req ->setSmsFreeSignName( "学生惠" );//来源于配置短信签名 下面列表中有签名名称
                      //$code = '1234';
                      $code= rand(100000,999999);//随机六位验证码
                      F('liuq/up/pengfei',$code);
                      $product = '学生惠密码';
                      $req ->setSmsParam( "{code:'{$code}',product:'{$product}'}" ); //变量来源于 配置短信模板 点击列表中的详情 模板内容的变量
                      $req ->setRecNum( $tell ); //手机号
                      $req ->setSmsTemplateCode("SMS_75850145"); //配置短信模板 列表中有模板id
                      $resp = $c ->execute( $req );
                      //var_dump($resp);
                      return $resp;
                  }
       

  public  function tests(){
 $tell = '13624012805';
// 判断是否有这个查询缓存    

    $arr = S('gggg',$tell); //设置缓存的生存时间 
    
    dump($arr);exit;
  }





}